import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

const app = createApp(App)

// 全局初始化样式
import './assets/css/init.css'
// 引入icon
import './assets/icon-font/iconfont.css'
// 引入animate.css
import 'animate.css'

// 注册全局组件
import PageView from '@/components/PageView.vue'
app.component("page-view", PageView)
import PageHeader from '@/components/PageHeader.vue'
app.component("page-header", PageHeader)

// Toast
import { showToast, setToastDefaultOptions } from 'vant';
import 'vant/es/toast/style';
setToastDefaultOptions('loading', { forbidClick: true });

// Dialog
import { showDialog } from 'vant';
import 'vant/es/dialog/style';

// Notify
import { showNotify } from 'vant';
import 'vant/es/notify/style';

// ImagePreview
import { showImagePreview } from 'vant';
import 'vant/es/image-preview/style';

import { Lazyload } from 'vant';
app.use(Lazyload, {
    lazyComponent: true,
    loading: require("./assets/image/loading.gif"),
    error: require("./assets/image/error.jpeg"),
    attempt: 3
});

// 长按指令
app.directive("longpress", {
    mounted(el, binding, vnode, oldVnode) {
        let timeout = binding.arg || 500
        let timeId = null
        el.addEventListener("touchstart", e => {
            timeId = setTimeout(() => {
                binding.value.call(vnode.context, e)
            }, timeout)
        })
        el.addEventListener("touchmove", e => clearTimeout(timeId))
        el.addEventListener("touchend", e => clearTimeout(timeId))
        el.addEventListener("touchcancel", e => clearTimeout(timeId))
    }
})

app.use(store).use(router).mount('#app')
